
//查询 按钮 点击事件
$("#search_btn").click(function(){table.fnDraw();  });
//刷新 按钮 点击事件
function _refresh(){ window.location.href=action_url+"list.do";}
function _refresh(param){window.location.href=action_url+"list.do?"+param;}
function _refresh_1(url,param){ window.location.href=url+"?"+param;}



function _add(title,url,w,h){layer_show(title,url,w,h);}
function _edit(title,url,w,h){layer_show(title,url,w,h);}

/*批量删除*/
function datadel(){
	var select_size=$("input[name='ck_id']:checked").size();
	if(select_size==0){layer.alert('请选择要删除的数据！');return;}
	var id_str="";
	$("input[name='ck_id']:checked").each(function() {id_str+=$(this).val()+"_"; });
    layer.confirm("确认要删除选中的【"+select_size+"】条数据吗？",function(index){
	    $.ajax({ type: 'POST', dataType: "json",url: action_url+"do_batchDelete.do" ,
	     data: "id_str="+id_str ,
	     success: function(data){
	    	 if(_opAlert_special(data)){ table.fnDraw(); layer.msg(data.resultMsg,{icon:6,time:1500});}
	    	 else{layer.msg(data.resultMsg,{icon:5,time:3000});}
	   	 } 
		});
	});
}

/*删除*/
function _del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
	    $.ajax({ type: 'POST', dataType: "json",url: action_url+"do_delete.do" ,
	     data: "id="+id ,
	     success: function(data){
	    	 if(_opAlert_special(data)){ table.fnDraw(); layer.msg(data.resultMsg,{icon:6,time:1500});}
	    	 else{layer.msg(data.resultMsg,{icon:5,time:3000});}
	   	 } 
		});
	});
}

/*发送Ajax请求*/
function _ajax(url,data){
    $.ajax({ type: 'POST', dataType: "json",url: url ,data: data ,
    		success: function(data){ if(_opAlert_special(data)){ return data;}} 
	});
}

/*弹出子页面 全屏模式*/
function _index(title,url){ 
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/* 关闭 子页面 */
function _return(){
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}
/* 关闭 子页面 并刷新父页面 */
function _returnParent(){
	parent.table.fnDraw(); //刷新父页面数据
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}

/* 关闭 子页面 并刷新父页面 */
function _opAlert(data){ 
	if(data.resultCode=="00"){//提示信息
 		parent.layer.msg(data.resultMsg,{icon:6,time:1500});
 		parent.table.fnDraw(); //刷新父页面数据
   		parent.layer.close(parent.layer.getFrameIndex(window.name));
  	}else if(data=="9999"){
  		alert("登录超时,请重新登录!");
  		window.parent.location.href='/login.jsp';
  	}else{
  		parent.layer.msg(data.resultMsg,{icon:5,time:3000});
  	}
} 

/* 处理请求的数据，并返回obj ，type  */
function _opAlert_special(data){ 
	if(data=="9999"){
  		alert("登录超时,请重新登录!");
  		window.parent.location.href='/login.jsp';
  		return false;
  	}else if(data.resultCode == "00"){
  		return true;
  	} 
	//parent.layer.msg(data.resultMsg,{icon:5,time:3000});
	return false;
} 

function _listAlert(json){
	if(json=="9999"){
  		alert("登录超时,请重新登录!");
  		window.parent.location.href='/login.jsp';
  		return false;
  	}
  	return true;
}

/* 弹出新窗口 */
function pop_page(url){  
    var iWidth=700;                          //弹出窗口的宽度;
    var iHeight=600;                        //弹出窗口的高度;
    var iTop = (window.screen.availHeight-30-iHeight)/2;       //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth-10-iWidth)/2;           //获得窗口的水平位置;
	window.open(url,"_blank",'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=yes,location=no,status=no');
}

//js获取项目根路径，如： http://localhost:8083/uimcardprj
function getRootPath(){
    var curWwwPath=window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht=curWwwPath.substring(0,pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    return(localhostPaht+projectName);
}